#!/bin/bash

# shell 通过 adb 启动钉钉，同时配合钉钉自动打卡进行打卡操作
# crontab 启动
# 1 9 * * * bash /home/jason/sh/adb_ding_talk.sh >> /home/jason/sh/adb.log 2>&1
# 41 19 * * * bash /home/jason/sh/adb_ding_talk.sh >> /home/jason/sh/adb.log 2>&1

source /etc/profile
echo "************************************"
echo "开始打卡"
date
function rand(){
    min=$1
    max=$(($2-$min+1))
    num=$(($RANDOM+1000000000)) #增加一个10位的数再求余
    echo $(($num%$max+$min))
}

rnd=$(rand 10 2000)

echo "开始随机等待 $rnd 秒..."
# 随机等待
sleep $rnd
date
echo "等待后继续"


adb -s CJL7N16201017768 shell input keyevent 224
echo "点亮屏幕"

# 我通过开发者模式关掉锁屏了，所以不需要
adb -s CJL7N16201017768 shell input swipe 300 1000 300 500
echo "滑动屏幕解锁"

echo "找到钉钉并打开"
adb -s CJL7N16201017768 shell am start -n com.alibaba.android.rimet/com.alibaba.android.rimet.biz.LaunchHomeActivity
echo "睡一会"
sleep 15
adb -s CJL7N16201017768 shell input keyevent 26

echo "结束打卡"
exit 0